import Vue from 'vue'
import VueRouter from 'vue-router';
import { titleController } from "@/utils";
import progressBar from "./progressBar";



Vue.use(VueRouter)



const routes = [
  { path: "/", name: "Home", component: progressBar(() => import(/* webpackChunkName: "home" */ "@/views/Home")), meta: { title: "首页" } },
  { path: "/blog", name: "Blog", component: progressBar(() => import(/* webpackChunkName: "blog" */ "@/views/Blog")), meta: { title: "文章" } },
  { path: "/blog/cate/:catgoryid", name: "CategoryBlog", component: progressBar(() => import(/* webpackChunkName: "CategoryBlog" */ "@/views/Blog")), meta: { title: "文章" } },
  { path: "/blog/:id", name: "BlogDetail", component: progressBar(() => import(/* webpackChunkName: "BlogDetail" */ "@/views/Blog/Detail")), meta: { title: "文章详情" } },
  { path: "/project", name: "Project", component: progressBar(() => import(/* webpackChunkName: "project" */ "@/views/Project")), meta: { title: "项目&效果" } },
  { path: "/message", name: "Message", component: progressBar(() => import(/* webpackChunkName: "message" */ "@/views/Message")), meta: { title: "留言板" } },
  { path: "/about", name: "About", component: progressBar(() => import(/* webpackChunkName: "about" */ "@/views/About")), meta: { title: "关于我" } },
  {name: "NotFound", path: "*", component: progressBar(() => import(/* webpackChunkName: "NotFound" */ "@/views/NotFound"))}
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
router.afterEach((to, from) => {
  if (to.meta.title) {
    titleController.setRouteTitle(to.meta.title);
  }
})

export default router
